home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
CT Explorer
/
OpenGLSliceDrawer.cs
< prev
next >
Wrap
Text File
|
2005-06-09
|
2KB
|
100 lines
using System;
using CsGL.OpenGL;
using SampleGUI;
using System.ComponentModel;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
public enum DRAW_METHOD
{
GRIDDED_SQUARES,
PIXELATED_SQUARES,
POINTS
}
public class SliceDrawer
{
private ElementIndexer3D indexer;
public ElementIndexer3D Indexer
{
get
{
return indexer;
}
set
{
indexer = value;
}
}
public DRAW_METHOD DrawMethod;
//constructor
public SliceDrawer()
{
}
//change to
public void DrawSlice(Scan s, int normalAxis)
{
//define axis that are coplanar with the slice
AXIS[] planarAxes = new AXIS[2];
int[] dim = new int[2];
//float[] pixelScale = new float[3]; //scale pixels for gridded databy dim+1/dim
int idx = 0;
indexer.RCPIndex = s.DimensionSize;
//TO DO: Figure out how to match up low res and high res images
for(int i = 0; i < 3; i++)
{
if(i != (int)normalAxis)
{
planarAxes[idx] = (AXIS)i;
dim[idx] = Math.Abs(indexer.GetXYZElement((int)planarAxes[idx]));
if(DrawMethod.Equals(DRAW_METHOD.GRIDDED_SQUARES))
{
// pixelScale[i] = dim[idx]/(float)(dim[idx]-1);
dim[idx]--;
}
// else
// pixelScale[i] = 1.0f;
idx++;
}
//else
// pixelScale[i] = 1.0f; //pixel scale in orthogonal direction is always 1
}
//get size in x,y,z
indexer.RCPIndex = s.DimensionSize;
float gray;
int window = s.Window;
int level = s.Level;
int[] di = {0,0,1,1}; //index offsets for each of the 4 corners
int[] dj = {0,1,1,0}; //index offsets for each of the 4 corners
indexer.RCPIndex = s.SliceIndex;
for(int i = 0; i < dim[0]; i++) //iterate through scan matrix dimension 1
{
for(int j = 0; j < dim[1]; j++) //iterate through scan matrix dimension 2
{
GL.glBegin(GL.GL_QUADS);
for(int k = 0; k < 4; k++) //iterate through each corner of the quad
{
indexer.SetXYZElement((int)planarAxes[0],i+di[k]);
indexer.SetXYZElement((int)planarAxes[1],j+dj[k]);
if(DrawMethod.Equals(DRAW_METHOD.GRIDDED_SQUARES) || k.Equals(0))
{
gray = s.Data[indexer.Row,indexer.Column,indexer.Plane];
gray = (gray-(level-window/2))/(float)window;
GL.glColor3f(gray,gray,gray);
}
GL.glVertex3f(indexer.X,indexer.Y,indexer.Z);
}//for k
GL.glEnd();
}//for j
}//for i
}//DrawSlice
}